<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let str = "how are you you rmx rmx";
      let reg = /[a-zA-Z]+/gi;
      let arr = str.match(reg);
      console.log(arr);
      let setArr = [...new Set(arr)];
      console.log(setArr)
        
      let bigArr = [];
      setArr.forEach((item) => {
        bigArr.push(arr.filter((item2) => item2 === item));
      });
      console.log(bigArr)
      let result = [];
      bigArr.forEach((item) => {
        result.push({
          key: item[0],
          length: item.length,
        });
      });
      result = result.sort((a, b) => a.length - b.length);
      console.log(result)
    </script>
  </body>
</html>
